import Taro from '@tarojs/taro';

/**
 * 下划线转驼峰
 * @param str
 * @returns {*}
 */
export function lineToCamelCase(targetString) {
  return targetString.replace(/_(\w)/g, function (match, letter) {
    // _s  s
    // _f   f
    return letter.toUpperCase();
  });
}

/**
 * 驼峰转下划线
 * @param str
 * @returns {*}
 */
export function camelCaseToLine(targetString) {
  return targetString.replace(/([A-Z])/g, function (match) {
    return "_" + match.toLowerCase();
  });
}

/**
 * @description: 年涨幅/日涨幅
 * @event:
 * @return {*}
 */
export function getIncrease(num1, num2) {
  if (num2 != 0 && !isNaN(num2)) {
    return (Number(num1) - Number(num2)) / Number(num2)
  } else {
    return 0
  }

}
/**
 * @description: 获取数据中的最大最小值
 * @event:
 * @param {any} data
 * @return {*}
 */
export function getNumber(data: any) {

  const maxValue = Math.ceil(Math.max.apply(null, data));
  const minData = Math.min.apply(null, data);
  const minfloor = Math.floor(Math.min.apply(null, data));
  const minValue = minfloor === minData ? minData - 1 : minfloor;
  return {
    maxValue,
    minData,
    minfloor,
    minValue
  }

}
/**
 * @description: 获取自定义navbar高度
 * @event:
 * @return {*}
 */
export function getNavBarHeight() {
  let menuButtonObject = Taro.getMenuButtonBoundingClientRect(); //获取胶囊对象
  var sysinfo = Taro.getSystemInfoSync(); // 获取设备系统对象
  let statusBarHeight = sysinfo.statusBarHeight; // 获取状态栏高度
  let menuBottonHeight = menuButtonObject.height; //获取胶囊顶部高度
  let menuBottonTop = menuButtonObject.top; // 获取胶囊距离顶部的高度
  let result = statusBarHeight + menuBottonHeight + (menuBottonTop - statusBarHeight) * 2;
  return result
}


export function isFunction(fn) {
  return Object.prototype.toString.call(fn) === '[object Function]';
}
